﻿using RH.USER.MODEL.Db;
using RH.USER.MODEL.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace RH.USER.DAL.Repository
{
    public class UserRepository : IUserRepository
    {
        public readonly MyDbContext _context;

        public UserRepository(MyDbContext myDbContext)
        {
            _context = myDbContext;
        }

        
        public async Task<User> GetAsyncUserInfo(string username)
        {
            return await _context.Users
                                 .FirstOrDefaultAsync(u => u.UserName == username);
        }

        public async Task AddUser(User user)
        {

            await _context.Users.AddAsync(user);
            await _context.SaveChangesAsync();

        }
        public async Task<string> GetUserPasswordAsync(string userName)
        {
            var user = await _context.Users.FirstOrDefaultAsync(u => u.UserName == userName);
            return user?.UserPassword; // 如果找不到用户，返回 null
        }
    }
}
